﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;
using IHotelDal;
using System.Threading.Tasks;
using System.Data;
using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace HotelDal.DishDAL
{
    public class DishiDal : IDish
    {
        MyDbcontext db = new MyDbcontext();
        /// <summary>
        /// 添加新菜品
        /// </summary>
        /// <param name="dishesInfo"></param>
        /// <returns></returns>
        public int AddDish(DishesInfo dishesInfo)
        {
            db.DishesInfo.Add(dishesInfo);
            return db.SaveChanges();
        }
        /// <summary>
        /// 添加点菜单
        /// </summary>
        /// <param name="dishedInfo"></param>
        /// <returns></returns>
        public int AddDished(DishedInfo dishedInfo)
        {
            db.DishedInfo.Add(dishedInfo);
            return db.SaveChanges();
        }

        /// <summary>
        /// 添加菜品销售单
        /// </summary>
        /// <param name="dishSales"></param>
        /// <returns></returns>
        public int AddDishSale(DishSalesInfo dishSales)
        {
            db.DishSalesInfo.Add(dishSales);
            return db.SaveChanges();
        }
        /// <summary>
        /// 删除菜品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public int DelDish(int id)
        {
            var did = db.DishesInfo.Find(id);
            db.DishesInfo.Remove(did);
            return db.SaveChanges();
        }

        /// <summary>
        /// 菜品列表
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<DishesInfo> GetDishes()
        {
            List<DishesInfo> list = (from s in db.DishesInfo
                                   //  join a in db.DishLei on s.DishLei equals a.Id
                                     select new DishesInfo

                                     {
                                         DishiId = s.DishiId,
                                         DishName = s.DishName,
                                         DishPrice = s.DishPrice,
                                         DishLei = s.DishLei,
                                         DishPicture = s.DishPicture,
                                         
                                        
                                     }).ToList();
            return list;
        }
        /// <summary>
        /// 显示菜品分类
        /// </summary>
        /// <returns></returns>
        public List<DishLei> GetDishLeis()
        {
            List<DishLei> list = (from s in db.DishLei
                                  select new DishLei
                                  {
                                      Id = s.Id,
                                      Name = s.Name
                                  }

                ).ToList();
            return list;
        }

        /// <summary>
        /// 菜品销售单
        /// </summary>
        /// <returns></returns>
        public List<DishSalesInfo> GetDishSales()
        {
            List<DishSalesInfo> list = (from s in db.DishSalesInfo
                                        join a in db.DishesInfo on s._DishiId equals a.DishiId
                                        select new DishSalesInfo

                                        {
                                            DishedtokenId = s.DishedtokenId,
                                            DishPay = s.DishPay,
                                            _DishEndTime = s._DishEndTime,
                                            _DishiId = s._DishiId,
                                            Amount = s.Amount,
                                            _Zid = s._Zid
                                        }).ToList();
            return list;
        }

        public int UpDishPrice(DishesInfo dishes)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 修改菜品价格
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

    }
}
